Conditions | 1 |
Paths | 1 |
Total Lines | 89 |
Code Lines | 60 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | "use strict"; |
||
11 | describe("gulp-yaml-include", function () { |
||
12 | it("should work in buffer mode", function (done) { |
||
13 | var stream = index(); |
||
14 | var testFile = new gutil.File({ |
||
15 | base: __dirname, |
||
16 | cwd: __dirname, |
||
17 | path: path.join(__dirname, 'test.yaml'), |
||
18 | contents: fs.readFileSync(path.join(__dirname, "test.yaml")) |
||
19 | }); |
||
20 | |||
21 | stream.on("data", function () { |
||
22 | assert.equal("paths:\n a: b\n", testFile.contents.toString()); |
||
23 | }); |
||
24 | |||
25 | stream.on("end", function () { |
||
26 | done(); |
||
27 | }); |
||
28 | |||
29 | stream.write(testFile); |
||
30 | stream.end(); |
||
31 | }); |
||
32 | |||
33 | it("should work in stream mode", function (done) { |
||
34 | var stream = index(); |
||
35 | var testStream = new PassThrough(); |
||
36 | var testFile = new gutil.File({ |
||
37 | base: __dirname, |
||
38 | cwd: __dirname, |
||
39 | path: path.join(__dirname, 'test.yaml'), |
||
40 | contents: testStream |
||
41 | }); |
||
42 | testStream.write(fs.readFileSync(path.join(__dirname, "test.yaml"))); |
||
43 | testStream.write(Buffer.from("\n")); |
||
44 | testStream.write(Buffer.from("c: 1")); |
||
45 | testStream.end(); |
||
46 | |||
47 | stream.on("data", function (newFile) { |
||
48 | newFile.pipe(es.wait(function(err, data) { |
||
49 | assert.equal("paths:\n a: b\nc: 1\n", data.toString()); |
||
50 | })); |
||
51 | }); |
||
52 | |||
53 | stream.on("end", function () { |
||
54 | done(); |
||
55 | }); |
||
56 | |||
57 | stream.write(testFile); |
||
58 | stream.end(); |
||
59 | }); |
||
60 | |||
61 | it("should let null files pass through", function (done) { |
||
62 | var stream = index(), |
||
63 | n = 0; |
||
64 | stream.pipe(es.through(function (file) { |
||
65 | assert.equal(file.path, "null.yaml"); |
||
66 | assert.equal(file.contents, null); |
||
67 | n++; |
||
68 | }, function () { |
||
69 | assert.equal(n, 1); |
||
70 | done(); |
||
71 | })); |
||
72 | stream.write(new gutil.File({ |
||
73 | path: "null.yaml", |
||
74 | contents: null |
||
75 | })); |
||
76 | stream.end(); |
||
77 | }); |
||
78 | |||
79 | it("should work subdir inc", function (done) { |
||
80 | var stream = index(); |
||
81 | var testFile = new gutil.File({ |
||
82 | base: __dirname, |
||
83 | cwd: __dirname, |
||
84 | path: path.join(__dirname, 'base.yaml'), |
||
85 | contents: fs.readFileSync(path.join(__dirname, "base.yaml")) |
||
86 | }); |
||
87 | |||
88 | stream.on("data", function () { |
||
89 | assert.equal("version: 1\nsub:\n hoge: fuga\n", testFile.contents.toString()); |
||
90 | }); |
||
91 | |||
92 | stream.on("end", function () { |
||
93 | done(); |
||
94 | }); |
||
95 | |||
96 | stream.write(testFile); |
||
97 | stream.end(); |
||
98 | }); |
||
99 | }); |
||
100 |